<?php
namespace App\Service\BMR;
use App\Service\BMR\Metabolize\BasialMetabolize;
use App\Service\BMR\Metabolize\Metabolize;
use App\Service\BMR\Metabolize\Person;

/**基础代谢
 * Class BMR_Metabolize
 * @package App\Service\BMR
 */
class BMR_Metabolize {
    const TYPE_ADD = 'up';
    const TYPE_DEL = 'down';
    /**
     * @var \App\Service\BMR\Metabolize\Person
     */
    protected $person;

    /**
     * @var \App\Service\BMR\Metabolize\Metabolize
     */
    protected $metabolize;

    /**设置性别
     * @param Person $person
     * @return $this
     */
    public function setPerson(Person $person) {
        $this->person = $person;
        return $this;
    }
    public function setMetabolize(Metabolize $metabolize) {
        $this->metabolize = $metabolize;
        return $this;
    }

    /**性别对应基础热量
     * @param Metabolize $metabolize
     * @return float
     */
    public function baseHot(Metabolize $metabolize) {
        return $this->person->accept($metabolize);
    }

    /**获取重量热量
     * @param $type up 增肌，down 减肌
     * @param $weight kg 重量
     * @return float
     */
    public function getWeightHot($type, $weight) {
        $data = round(7700 * $weight/30, 2);
        if ($type == static::TYPE_DEL) $data = -$data;
        return $data;
    }

    /** 运动周期
     * @param Metabolize $metabolize 基础代谢类
     * @param float $cycle 运动周期
     * @param float $weight 增加热量，或者减少热量
     * @return mixed
     */
    public function totalHot(Metabolize $metabolize , float $cycle, float $weight = 0) {
        return $this->baseHot($metabolize) * $cycle + $weight;
    }
}